﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CodeGame.ServerObjects;

namespace CodeGame.Networking.Serverside.ClientServerPackets
{
    class MoveEntityRequest : ServerPacket
    {
        public override ClientServerNet GetID()
        {
            return ClientServerNet.EntityMoveRequest;
        }

        public override void Handle(Lidgren.Network.NetIncomingMessage message, Lidgren.Network.NetConnection sender)
        {
            string str = message.ReadString();
            int amount = message.ReadInt32();

            Player ply = ServerSingletons.Players.GetPlayer(sender);

            if (amount < 0)
            {
                if (ply.WithdrawResouces((int)(-amount * Balence.MoveEntity)))
                {
                    ServerSingletons.World.GetEntity(true, str).Move(str, amount);
                }
            }
            else
            {
                if (ply.WithdrawResouces((int)(amount * Balence.MoveEntity)))
                {
                    ServerSingletons.World.GetEntity(true, str).Move(str, amount);
                }
            }
        }
    }
}
